package com.xgit.iov.work.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xgit.iov.common.core.util.R;
import com.xgit.iov.common.log.annotation.LogAnnotation;
import com.xgit.iov.work.model.DbdSim;
import com.xgit.iov.work.service.IDbdSimService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * SIM卡管理
 *
 * @author william
 * @date 2020-10-19
 */

@Api(tags = "SIM卡API")
@RestController
@RequestMapping("/sim")
public class DbdSimController {

    @Autowired
    private IDbdSimService dbdSimService;

    /**
     * 查询SIM卡列表
     */
    @ApiOperation(value = "查询SIM卡列表")
    @GetMapping("/page")
    public R page(Page page, DbdSim dbdSim) {
        return R.ok(dbdSimService.selectDbdSimPage(page,dbdSim));
    }


    /**
     * 获取SIM卡详细信息
     */
    @ApiOperation(value = "获取SIM卡详细信息")
    @GetMapping(value = "/{id}")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(dbdSimService.getById(id));
    }

    /**
     * 新增SIM卡
     */
    @ApiOperation(value = "新增SIM卡")
    @LogAnnotation("新增SIM卡")
    @PostMapping(value = "/save")
    @PreAuthorize("@pms.hasPermission('work_sim_add')")
    public R save(@Valid @RequestBody DbdSim dbdSim) {
        return R.ok(dbdSimService.insertDbdSim(dbdSim));
    }

    /**
     * 修改SIM卡
     */
    @ApiOperation(value = "修改SIM卡")
    @LogAnnotation("修改SIM卡")
    @PutMapping(value = "/update")
    @PreAuthorize("@pms.hasPermission('work_sim_edit')")
    public R update(@Valid @RequestBody DbdSim dbdSim) {
        return R.ok(dbdSimService.updateDbdSim(dbdSim));
    }

    /**
     * 删除SIM卡
     */
    @ApiOperation(value = "删除SIM卡")
    @LogAnnotation("删除SIM卡")
	  @DeleteMapping("/{ids}")
    @PreAuthorize("@pms.hasPermission('work_sim_del')")
    public R remove(@PathVariable Long[] ids) {
        return R.ok(dbdSimService.deleteDbdSimByIds(ids));
    }
}
